package cn.iocoder.yudao.module.famous.doctor.controller.admin.video;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.video.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.video.FamVideoDO;
import cn.iocoder.yudao.module.famous.doctor.convert.video.FamVideoConvert;
import cn.iocoder.yudao.module.famous.doctor.service.video.FamVideoService;

@Tag(name = "管理后台 - 视频管理")
@RestController
@RequestMapping("/famous.doctor/fam-video")
@Validated
public class FamVideoController {

    @Resource
    private FamVideoService famVideoService;

    @PostMapping("/create")
    @Operation(summary = "创建视频管理")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:create')")
    public CommonResult<Long> createFamVideo(@Valid @RequestBody FamVideoCreateReqVO createReqVO) {
        return success(famVideoService.createFamVideo(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新视频管理")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:update')")
    public CommonResult<Boolean> updateFamVideo(@Valid @RequestBody FamVideoUpdateReqVO updateReqVO) {
        famVideoService.updateFamVideo(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除视频管理")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:delete')")
    public CommonResult<Boolean> deleteFamVideo(@RequestParam("id") Long id) {
        famVideoService.deleteFamVideo(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得视频管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:query')")
    public CommonResult<FamVideoRespVO> getFamVideo(@RequestParam("id") Long id) {
        FamVideoDO famVideo = famVideoService.getFamVideo(id);
        return success(FamVideoConvert.INSTANCE.convert(famVideo));
    }

    @GetMapping("/list")
    @Operation(summary = "获得视频管理列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:query')")
    public CommonResult<List<FamVideoRespVO>> getFamVideoList(@RequestParam("ids") Collection<Long> ids) {
        List<FamVideoDO> list = famVideoService.getFamVideoList(ids);
        return success(FamVideoConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得视频管理分页")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:query')")
    public CommonResult<PageResult<FamVideoRespVO>> getFamVideoPage(@Valid FamVideoPageReqVO pageVO) {
        PageResult<FamVideoDO> pageResult = famVideoService.getFamVideoPage(pageVO);
        return success(FamVideoConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出视频管理 Excel")
    @PreAuthorize("@ss.hasPermission('famous.doctor:fam-video:export')")
    @OperateLog(type = EXPORT)
    public void exportFamVideoExcel(@Valid FamVideoExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<FamVideoDO> list = famVideoService.getFamVideoList(exportReqVO);
        // 导出 Excel
        List<FamVideoExcelVO> datas = FamVideoConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "视频管理.xls", "数据", FamVideoExcelVO.class, datas);
    }

}
